<?php
/**
 * @author GhostWei
 * @date 2012-7-16
 */
class controller_www_category extends front_controller_panel {
	
	public function action_index() {
		$this->getRequest()->setActionName('list');
		$this->action_list();
	}
	
	public function action_html() {
		$this->action_index();
	}
	
	public function action_list() {
		$name = trim($this->_param('name'));
		$this->view->category = $category = $this->cache()->category()->getInformation(array('name' => $name));
		if(!$category) {
			throw new front_exception($this->language('该分类不存在'), 404);
		}
		$id = $category['id'];
		$where1 = "`lang` = '{$this->lang}' AND `category_id` = '$id'";
		$where2 = "`category_id` IN(
						SELECT a.`id` FROM `picture_category` AS a 
						INNER JOIN `picture_category_locale` AS b 
						ON a.id = b.category_id 
						WHERE b.`parent_id` = '$id' AND b.`lang` = '{$this->lang}')";
		$sql = "SELECT `special_id` FROM `picture_special_category` WHERE ($where1) OR ($where2)";
		$adapter = new system_paginator_adapter_concept(new picture_special_concept($this->lang));
		$adapter->setCurrentPageNumber(intval($this->_param('page', 1)));
		$adapter->setLimit(20);
		$adapter->where("special.ptotal > 0 AND special.id IN($sql)");
		$this->view->headDescription = $category['title'];
		$this->view->specialList = new system_paginator($adapter);
		$this->_crumbs()->addPage(system_nav_page::create($category['title'])->setRoute('category/list')->setParams(array('name' => $name)));
		$this->render();
	}
	
}
